<%--
  Created by IntelliJ IDEA.
  User: EDY
  Date: 2023-11-01
  Time: 8:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="../../js/jquery-3.3.1.js"></script>
    <script src="../../js/bootstrap-table.min.js"></script>
    <script src="../../js/bootstrap.bundle.min.js"></script>
    <script src="../../js/bootstrap-table-zh-CN.min.js"></script>
    <script src="../../js/jquery.form.js"></script>
    <script src="../../js/jquery.validate.js"></script>
    <script src="../../js/messages_zh.js"></script>
    <script src="js/update.js"></script>
    <link rel="stylesheet" href="../../css/bootstrap-table.min.css"></link>
    <link rel="stylesheet" href="../../css/bootstrap.min.css"></link>
    <style>
        #form {
            position: absolute;
            top: 10%;
            bottom: 10%;
            left: 10%;
            right: 10%;
            margin: auto;
        }
    </style>
</head>
<body onload="infoShow()">
<table width="100%">
    <tbody>
    <tr height="20">
        <td>
            <span style="color: #0c84ff">您正在做的业务是：生产管理--产品生产工序设计--制定产品生产工序设计单</span>
        </td>
    </tr>
    <tr height="20">
        <td align="right">
            <input id="add" type="button" value="添加工序">
            <input id="del" type="button" value="删除工序">
            <input type="button" onclick="register()" value="提交">
            <input type="button" onclick="history.back()" value="返回">
        </td>
    </tr>
    </tbody>
</table>
<div>
    <table width="80%" align="center" border="0" bgcolor="#FFFFFF">
        <tbody>
        <tr>
            <td rowspan="2">
                <table cellspacing="0" cellpadding="0" width="100%" style="border: #333333 1px solid;">
                    <tbody>
                    <tr>
                        <td colspan="4" height="10">
                            <table width="100%">
                                <tbody>
                                <tr>
                                    <td>
                                        <table align="center">
                                            <tbody>
                                            <tr height="20">
                                                <td align="center" height="5"><font size="4"><b>生产工序设计单</b></font>
                                                </td>
                                            </tr>
                                            </tbody>
                                        </table>
                                        <table align="center">
                                            <tbody>
                                            <tr height="20">
                                                <td align="center" height="5">&nbsp;</td>
                                            </tr>
                                            </tbody>
                                        </table>
                                        <table align="center" id="theObjTable">
                                            <tbody>
                                            <tr height="20px">
                                                <td align="right" width="10%">
                                                    产品名称：
                                                </td>
                                                <td width="30%">
                                                    <input type="text" readonly name="productName"
                                                           style="outline: none;border: 0px"></td>
                                                <td align="left" width="15%">
                                                    产品编号：
                                                </td>
                                                <td width="30%">
                                                    <input type="text" readonly name="productId"
                                                           style="outline: none;border: 0px">
                                                </td>
                                                </td>
                                            </tr>
                                            <tr height="20px">
                                                <td align="right" width="10%">
                                                    设计人：
                                                </td>
                                                <td width="35%">
                                                    <input type="text" name="designer"
                                                           style="outline: none;width: 100%;border:0px;border-bottom:1px solid;">
                                                </td>
                                            </tr>
                                            </tbody>
                                        </table>
                                        <table align="center">
                                            <tbody>
                                            <tr height="20">
                                                <td align="center" height="5">&nbsp;</td>
                                            </tr>
                                            </tbody>
                                        </table>
                                        <table border="1" cellspacing="0" cellpadding="0"
                                               align="center" id="tableOnlineEdit" style="text-align: center;">
                                            <thead>
                                            <tr height="20" bgcolor="#D2E9FF">
                                                <td bordercolor="#DEDBD6" align="left" width="5%">
                                                    点选
                                                </td>
                                                <td bordercolor="#DEDBD6" align="left"
                                                    width="13%">工序名称
                                                </td>
                                                <td bordercolor="#DEDBD6" align="left"
                                                    width="11%">工序编号
                                                </td>
                                                <td bordercolor="#DEDBD6" align="left"
                                                    width="13%">描述
                                                </td>
                                                <td bordercolor="#DEDBD6" align="left" width="8%">
                                                    工时数
                                                </td>
                                                <td bordercolor="#DEDBD6" align="left" width="8%">
                                                    工时单位
                                                </td>
                                                <td bordercolor="#DEDBD6" align="left"
                                                    width="11%">单位工时单价（元）
                                                </td>
                                                <td bordercolor="#DEDBD6" align="left"
                                                    width="13%">工时成本小计（元）
                                                </td>
                                            </tr>
                                            </thead>
                                        </table>
                                        <table align="center">
                                            <tbody>
                                            <tr height="20">
                                                <td align="center" height="5">&nbsp;</td>
                                            </tr>
                                            </tbody>
                                        </table>
                                        <table align="center">
                                            <tbody>
                                            <tr height="20px">
                                                <td align="right" width="10%">登记人：
                                                </td>
                                                <td width="30%">
                                                    <input type="text" name="register" value="${sysUsers.loginId}"
                                                           readonly
                                                           style="outline: none;width: 100%;border:0px;border-bottom:1px solid;">
                                                </td>
                                                <td align="left" width="10%">登记时间：
                                                </td>
                                                <td align="left" width="30%">
                                                    <input name="registerTime" readonly
                                                           style="border: 0px;outline: none">
                                                </td>
                                            </tr>
                                            <tr height="20">
                                                <td align="right" width="9%">设计要求：
                                                </td>
                                                <td align="left" colspan="3" width="89%">
                                                    <textarea rows="4" name="moduleDescribe"
                                                              style="width: 100%"></textarea>
                                                </td>
                                            </tr>
                                            </tbody>
                                        </table>
                                    </td>
                                </tr>
                                </tbody>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3" nowrap="" width="56">
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3" nowrap="" height="100"></td>
                        <td></td>
                    </tr>

                    <tr valign="bottom">
                        <td colspan="4" nowrap="" align="center"></td>
                    </tr>

                    <tr>
                        <td colspan="4" nowrap="" align="right"></td>
                    </tr>
                    </tbody>
                </table>
            </td>
            <td width="1" bgcolor="#ffffff" height="2"></td>
            <td width="1" bgcolor="#ffffff" height="2"></td>
            <td width="1" bgcolor="#ffffff" height="2"></td>
        </tr>
        <tr>
            <td width="1" bgcolor="#333333" height="120"></td>
            <td width="1" bgcolor="#666666" height="120"></td>
            <td width="1" bgcolor="#999999" height="120"></td>
        </tr>
        <tr valign="top" align="right">
            <td colspan="4">
                <table cellspacing="0" cellpadding="0" align="center" border="0">
                    <tbody>
                    <tr>
                        <td bgcolor="#333333" height="1"></td>
                    </tr>
                    <tr>
                        <td bgcolor="#666666" height="1"></td>
                    </tr>
                    <tr>
                        <td bgcolor="#999999" height="1"></td>
                    </tr>
                    </tbody>
                </table>
            </td>
        </tr>
        <tr valign="center" align="right">
            <td colspan="4"></td>
            <td valign="top" hidden bgcolor="#eeeeee" width="13%">
                <select name="select1" style="width:49%">
                    <option value="01/电子" selected="">01/电子</option>
                </select>
            </td>
            <td valign="top" hidden bgcolor="#eeeeee" width="13%">
                <select name="select2" style="width:49%">
                    <option value="01/计算机" selected="">01/计算机</option>
                </select>
            </td>
            <td valign="top" hidden bgcolor="#eeeeee" width="13%">
                <select name="select3" style="width:49%">
                    <option value="01/服务器" selected="">01/服务器</option>
                </select>
            </td>
        </tr>
        </tbody>
    </table>
</div>
<form class="modal fade" id="modalform" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content" style="width: 725px;height: 500px;position: absolute;left: -110px;">
            <h6><span style="color: #0c84ff">您正在做的业务是：生产管理--产品生产工序设计--制定产品生产工序设计单</span></h6>
            <div class="modal-header">
                <table class="table" id="DFileY0012Table" style="width: 690px">

                </table>
            </div>
        </div>
    </div>
</form>
<script>
    $(":input[name='registerTime']").val(new Date().toLocaleString())
    $(function () {
        $.post("../../DFile/showDFileById", {id: '${param.id}'}, function (data) {
            $.each(data, function (key, value) {
                if (key == "registerTime") {
                    return;
                }
                if (key == "register") {
                    return;
                }
                if (key == "productName") {
                    $("input[name=moduleProductName]").val(value)
                }
                if (key == "productId") {
                    $("input[name=moduleProductId]").val(value)
                }
                $("input[name=" + key + "]").val(value)
            })
        })
    })
    $("#add").click(function () {
        $("#modalform").modal("show");
    })
    $("#del").click(function () {
        if ($(":checkbox:checked").length == 0) {
            alert("请选择后再操作!")
            return
        }
        $(":checkbox:checked").each(function (index, intem) {
            $(intem).parent().parent().remove()
        })
    })

    function xj(number) {
        number = $(number);
        if (number.val() == "") {
            alert("数量不能为空")
            number.val(1)
        }
        var arr = number.val().split(".")
        number.val(arr[0])
        var num = number.parent().parent().find(":input[name='labourHourAmount']").val()
        var price = number.parent().parent().find(":input[name='costPrice']").val();
        var sum=num * price;
        number.parent().parent().find(":input[name='subtotal']").val(sum)
    }

    var i = 1;

    function rk(data) {
        data = JSON.parse(data)
        $.each(data, function (key, value) {
            if (key == "procedureId") {
                procedureId = value
            }
            if (key == "procedureName") {
                procedureName = value
            }
            if (key == "procedureDescribe") {
                procedureDescribe = value
            }
        })
        var tr = $("<tr>" +
            "<td><input type='checkbox' name='detailsNumber' style='width: 32px' value='" + i + "'></td>" +
            "<td><input name='procedureName' readonly style='outline: none;width:140px;border: 0px' value='" + procedureName + "'></td>" +
            "<td><input name='procedureId' readonly style='outline: none;width:120px;border: 0px' value='" + procedureId + "'></td>" +
            "<td><input name='procedureDescribe' readonly style='outline: none;width:120px;border: 0px' value='" + procedureDescribe + "'></td>" +
            "<td><input name='labourHourAmount' type='number' required onchange='xj(this)' style='border: 0px;width: 100px;background-color: #d5f8f1' min='1'></td>" +
            "<td><input name='amountUnit' style='outline: none;width:120px;border: 0px;background-color: #d5f8f1''></td>" +
            "<td><input name='costPrice' type='number' required onchange='xj(this)' style='border: 0px;width: 100px;background-color: #d5f8f1' min='1'></td>" +
            "<td><input name='subtotal' readonly style='outline: none;width:100px;border: 0px'>" +
            "</tr>")
        i = i + 1;
        var td = $("#tableOnlineEdit").find("td");
        var n = 0;
        $.each(td, function (index, item) {
            if ($(item).children().val() == procedureId) {
                n = 1;
            }
        })
        if (n != 1) {
            $("#tableOnlineEdit").append(tr);
        }
    }

    function register() {
        if ($(":checkbox").length == 0) {
            alert("请添加工序后再操作!")
            return
        }
        var productName = $("#theObjTable :input[name=productName]").val();
        var productId = $("#theObjTable :input[name=productId]").val();
        var designer = $("#theObjTable :input[name=designer]").val();
        var register = $(":input[name=register]").val();
        var registerTime = $(":input[name=registerTime]").val();
        var moduleDescribe = $(":input[name=moduleDescribe]").val();
        var select1 = $("select[name=select1]").val();
        var select2 = $("select[name=select2]").val();
        var select3 = $("select[name=select3]").val();
        var arr = new Array();
        var p = 0;
        $(":checkbox").each(function () {
            var detailsNumber = $(this).val()
            var procedureName = $(this).parent().parent().find("[name='procedureName']").val();
            var procedureId = $(this).parent().parent().find("[name='procedureId']").val();
            var procedureDescribe = $(this).parent().parent().find("[name='procedureDescribe']").val();
            var productDescribe = $(this).parent().next().next().next().next().children().val();
            var labourHourAmount = $(this).parent().parent().find(":input[name=labourHourAmount]").val();
            var amountUnit = $(this).parent().parent().find(":input[name=amountUnit]").val();
            var costPrice = $(this).parent().parent().find(":input[name=costPrice]").val();
            var subtotal = $(this).parent().parent().find(":input[name=subtotal]").val();
            var a = {
                detailsNumber: detailsNumber,
                procedureName: procedureName,
                procedureId: procedureId,
                procedureDescribe: procedureDescribe,
                productDescribe: productDescribe,
                labourHourAmount: labourHourAmount,
                amountUnit: amountUnit,
                costPrice: costPrice,
                subtotal: subtotal
            }
            if (p == 1) {
                return
            }
            if (labourHourAmount == "") {
                alert("工时数不能为空!")
                $(this).parent().parent().find(":input[name=labourHourAmount]").select()
                p = 1;
                return;
            }
            if (costPrice == "") {
                alert("单位工时单价不能为空!")
                $(this).parent().parent().find(":input[name=costPrice]").select()
                p = 1;
                return;
            }
            arr.push(a)
        });
        if (p == 1) {
            p = 0;
            return
        }
        var arr2 = {
            productName: productName,
            productId: productId,
            designer: designer,
            register: register,
            registerTime: registerTime,
            moduleDescribe: moduleDescribe,
            list: arr,
            select1: select1,
            select2: select2,
            select3: select3
        }
        $.ajax({
            url: "/MDesignProcedure/MDesignProcedureRegister",
            type: "post",
            data: JSON.stringify(arr2),
            contentType: 'application/json',
            dataType: "json",
            success: function (data) {
                alert(data.msg)
                if (data.code == '1') {
                    location.href = "register_locate.jsp";
                }
            }
        })
    }
</script>
</form>
</body>
</html>
